package com.clgk.wechatmall.partner.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.clgk.wechatmall.common.Response;
import com.clgk.wechatmall.common.ThreadLocals;
import com.clgk.wechatmall.common.sql.Page;
import com.clgk.wechatmall.manager.entity.ManagerVo;
import com.clgk.wechatmall.partner.bean.CityBean;
import com.clgk.wechatmall.partner.bean.PartnerBean;
import com.clgk.wechatmall.partner.service.PartnerService;


@Controller
@RequestMapping("partner")
public class PartnerAction {

	
	@Resource PartnerService partnerService;
	
	
	@RequestMapping("save")
	@ResponseBody
	public Response<Long> save(PartnerBean bean){
		Response<Long> response = new Response<Long>();
		if(bean.getId() != null){
			this.partnerService.update(bean);
			return response;
		}
		ManagerVo bu = ThreadLocals.getBackUser();
		bean.setManagerid(bu.getId());
		if(bean.getParentid() == null){
			bean.setParentid(bu.getPartnerid());
		}
		this.partnerService.save(bean);
		return response;
	}
	
	@RequestMapping("update")
	@ResponseBody
	public Response<Integer> update(PartnerBean bean){
		Response<Integer> response = new Response<Integer>();
		this.partnerService.update(bean);
		return response;
	}
	
	@RequestMapping("dels")
	@ResponseBody
	public Response<Integer> dels(String ids){
		Response<Integer> response = new Response<Integer>();
		this.partnerService.dels(ids);
		return response;
	}
	
	
	@RequestMapping("queryList")
	@ResponseBody
	public Response<List<PartnerBean>> queryList(PartnerBean par,Page page){
		Response<List<PartnerBean>> response = new Response<List<PartnerBean>>();
		response.setData(this.partnerService.queryList(par, page));
		response.setPage(page);
		return response;
	}
	
	@RequestMapping("queryTree")
	@ResponseBody
	public Response<List<PartnerBean>> queryTree(){
		Response<List<PartnerBean>> response = new Response<List<PartnerBean>>();
		response.setData(this.partnerService.queryTree());
		return response;
	}
	
	/**
	 * 获取区域信息列表
	 * @param city
	 * @return
	 */
	@RequestMapping("queryCityList")
	@ResponseBody
	public Response<List<CityBean>> queryCityList(CityBean city){
		Response<List<CityBean>> response = new Response<List<CityBean>>();
		response.setData(this.partnerService.queryCityList(city));
		return response;
	}
	
	/**
	 * 获取详情
	 * @param partnerid
	 * @return
	 */
	@RequestMapping(value = {"queryById","api/queryById"})
	@ResponseBody
	public Response<PartnerBean> queryById(Long partnerid){
		Response<PartnerBean> response = new Response<PartnerBean>();
		response.setData(partnerService.queryById(partnerid));
		return response;
	}
}
